#!/usr/bin/env python
# encoding: utf-8
"""
vector.py

Created by Morgan Quirk on 2007-08-28.
"""

import common

class Vector:
    def __init__(self, pos):
        self.x, self.y = pos
        
    def get_angle(self):
        return common.get_angle(self.x, self.y)
        
    def get_length(self):
        return common.get_dist(self.x, self.y)
        
    def get_length_sq(self):
        return common.get_dist_sq(self.x, self.y)
        
    def get_unit(self, newlen=1):
        d = common.get_dist(self.x, self.y)
        if d >0:
            return Vector((newlen*self.x/d, newlen*self.y/d))
        else:
            return Vector((0,0))
            
    def get_normal(self):
        return Vector((-self.y, self.x))
        
    def __add__(self, other):
        return Vector((self.x+other.x,self.y+other.y))
        
    def __sub__(self, other):
        return Vector((self.x-other.x,self.y-other.y))

    def __mul__(self, other):
        return Vector((self.x*other.x,self.y*other.y))
        
    def __div__(self, other):
        return Vector((self.x/other.x,self.y/other.y))                
        
    def dot(self, other):
        return (self.x*other.x + self.y*other.y)
        
    def project(self, other):
        dp = self.dot(other)
        unitb = other.get_unit()
        return Vector((dp*unitb.x, dp*unitb.y))
        